<?php


namespace app\common\model;

use think\Db;
use think\Model;

class WechatShareLink extends Model
{
    //判断是否已经生成过该链接了
    public static function hasLink($user_id,$mini_app_code,$product_id)
    {
        $res=self::where([
            'user_id'=>$user_id,
            'mini_app_code'=>$mini_app_code,
            'product_id'=>$product_id,
        ])->find();

        return $res;
    }

    //增加一个视频的链接地址
    public static function addVideoUrl($user_id,$video_url,$msg_id)
    {

        //随机数加时间戳，生成链接的no
        $no=rand(20000000,99999999). time();
        $data = [
            'user_id'=>$user_id,
            'no'=>$no,
            'mini_app_code'=>'movie',
            "product_id"=>0,
            'title'=>'复制分享链接可获取完整资源',
            'msg_id'=> $msg_id,
            "url" => '',
            "video_url" => $video_url,
            'add_time'=>time()
        ];
        $res=self::create($data);

        return $data;
    }


}
